#pragma once
#include "ispriteanimation.h"
#include "WareEngineNameSpace.h"

BEGIN_WARE

class IResourceManager;

class CSpriteAnimation : public ISpriteAnimation
{
public:
	CSpriteAnimation( ISpriteAnimationRes* pAniRes );
	~CSpriteAnimation(void);

	enum EPlaySate
	{
		PS_PLAY = 0,
		PS_PAUSE,
		PS_STOP,
	};

	virtual void			Stop();
	virtual void			Play();
	virtual void			Pause();
	virtual void			Update( uint32 uCurTime );

	virtual VBOOL			IsPlaying()								{ return m_eState == PS_PLAY; }

	virtual ITexture*		GetTexture();
	//virtual void			GetFrameRect( SIntRect& Rect );
	virtual VBOOL			SetAction( const VCHAR* szActionName );
	virtual void			SetPlaySpeed( float32 fPlaySpeed )		{ m_fPlaySpeed = fPlaySpeed; m_fRPlaySpeed = 1.0f / m_fPlaySpeed; }

	virtual const VCHAR*	GetActionName()							{ if( m_pCurAction ) { return m_pCurAction->strActionName.c_str(); } else { return NULL; } }

	virtual void			GetExtraInfo( SExtraInfo& ExtraInfo )	{ if( m_pCurAction ) { ExtraInfo = m_pCurAction->FrameList[m_nCurFrame]->ExtraInfo; } }

	virtual int32			GetTotleFrame( const VCHAR* szActionName );
	virtual int32			GetPerFrameTime( const VCHAR* szActionName );

	virtual int32			GetCurFrame()							{ return m_nCurFrame; }

	//////////////////////////////////////////////////////////////////////////
	void					SetResourceManager( IResourceManager* pResourceManager );
	ISpriteAnimationRes*	GetAnimationRes()						{ return m_pAnimationRes; }

	const string&			GetTextureFileName()					{ return m_pCurAction->FrameList[m_nCurFrame]->strTexture; }

private:

	ISpriteAnimationRes*	m_pAnimationRes;

	SAniActionInfo*			m_pCurAction;
	uint32					m_uStartTime;
	uint32					m_uPauseStartTime;
	uint32					m_nCurFrame;
	EPlaySate				m_eState;
	float32					m_fPlaySpeed;
	float32					m_fRPlaySpeed;

	IResourceManager*		m_pResourceManager;
};

END_WARE
